//
//  MHPopView.m
//  MHProgressPopUpView
//
//  Created by lanou on 15/10/30.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "MHPopView.h"
#import "ASProgressPopUpView.h"
@interface MHPopView()<ASProgressPopUpViewDataSource>
@property(nonatomic,strong)ASProgressPopUpView *loadingprogress;
@property(nonatomic,strong)NSMutableArray *imgesArr;
@property(nonatomic,strong)UIImageView *pictureImageView;

@end
@implementation MHPopView

-(NSMutableArray *)imgesArr
{
    if (_imgesArr==nil) {
        self.imgesArr=[NSMutableArray arrayWithCapacity:0];
    }
    return _imgesArr;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        self.pictureImageView=[[UIImageView alloc]initWithFrame:CGRectMake(30, 20, Width - 60, (Width - 60) * 7 / 8)];
        [self addSubview:self.pictureImageView];
        for (int i=1; i<=75; i++) {
            NSString *name=[NSString stringWithFormat:@"%d.tiff",i];
            NSString *path=[[NSBundle mainBundle]pathForResource:name ofType:nil];
            UIImage *img=[[UIImage alloc]initWithContentsOfFile:path];
            [self.imgesArr addObject:img];
        }
        self.pictureImageView.animationImages=self.imgesArr;
        self.pictureImageView.animationRepeatCount=0;
        self.pictureImageView.animationDuration=0.1*75;
        
        [self.pictureImageView startAnimating];
        

    self.loadingprogress =[[ASProgressPopUpView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
        
    
        self.loadingprogress.frame=CGRectMake(30, CGRectGetMaxY(self.pictureImageView.frame) + 40,Width-60 , 40);
        self.loadingprogress.dataSource=self;
        [self.loadingprogress showPopUpViewAnimated:YES];
        self.loadingprogress.font=[UIFont fontWithName:@"Futura-CondensedExtraBold" size:15];
        self.loadingprogress.popUpViewCornerRadius=10.0;
           self.loadingprogress.popUpViewAnimatedColors = @[[UIColor redColor], [UIColor orangeColor], [UIColor greenColor]];
        
        [self addSubview:self.loadingprogress];
        self.whiteView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Height, CGRectGetMaxX(self.loadingprogress.frame))];
        [self addSubview:self.whiteView];
    }
    return self;

}

-(NSString *)progressView:(ASProgressPopUpView *)progressView stringForProgress:(float)progress
{
    NSString *s;
    if (progress<0.2) {
        s=@"开始加载";
    }
    else if (progress>0.4&&progress<0.6)
    {
    s=@"加载一半左右";
    }
    else if(progress>0.75&&progress<1.0)
    {
    s=@"就快加载完了";
    }
    
    else if(progress>=1.0)
    {
    s=@"complete";
    }
    return s;
}
-(BOOL)progressViewShouldPreCalculatePopUpViewSize:(ASProgressPopUpView *)progressView
{
    return NO;
}
-(void)changeProgressValue:(CGFloat)progress
{
    [self.loadingprogress setProgress:progress animated:YES];
    if (self.loadingprogress.progress>1.0) {
        self.loadingprogress.progress=0.0;
    }
}
@end
